package com.baosight.sczx.zm.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * 
 * <p>Title: ServiceZM9G.java</p>
 * <p>Description: 首页安全统计--隐患统计 </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-12-13 上午05:47:54  郭淑芳  Create
 *</pre>
 */
public class ServiceZM9G extends ServiceEPBase {

	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化  </p>
	 * <p>return value: ServiceZM9G</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13上午05:48:16 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) 
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 隐患统计
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM9G</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13上午05:48:40 郭淑芳
	 * </p>
	 *
	 */
	public EiInfo query(EiInfo inInfo) {
		
		EiInfo outInfo = new EiInfo();		
		Map para1 = new HashMap();
		Map para2 = new HashMap();

		String fdCurrentDate = StaticTools.getDate(); // 当前日期
		String fdBeginDate = StaticTools.getFirDay(fdCurrentDate); // 当月开始日期
		System.out.println("fdBeginDate:" + fdBeginDate);

		para1.put("fdBeginDate", fdBeginDate);
		para1.put("fdCurrentDate", fdCurrentDate);
		para1.put("rownum", "10");

		para2.put("fdBeginDate", fdBeginDate);
		para2.put("fdCurrentDate", fdCurrentDate);
		
		

		//隐患地点分布统计查询
		outInfo.addBlock("result").addBlockMeta(initMetaData());
		outInfo.getBlock("result").addRows(dao.query("ZM9G.queryForIndexRisk", para1));

		// 查询本月隐患个数排名前五的地点
		outInfo.addBlock("riskResult").addBlockMeta(getMeta());
		outInfo.getBlock("riskResult").addRows(dao.query("ZM9G.queryForRiskPlace", para2));
		
		// 查询本月隐患个数排名前五的地点
		outInfo.addBlock("ternateResult").addBlockMeta(getMeta());
		outInfo.getBlock("ternateResult").addRows(dao.query("ZM9G.queryForTernateDept", para2));

		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: initMetaData</p>
	 * <p>Description: 初始化 EiBlockMeta（隐患地点分布统计查询结果block） </p>
	 * <p>return value:EiBlockMeta</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13上午05:51:11 郭淑芳
	 * </p>
	 *
	 */
	public static EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();
		EiColumn eiColumn;

		eiColumn = new EiColumn("fdDepartment");
		eiColumn.setType("C");
		eiColumn.setFieldLength(32);
		eiColumn.setDescName("部门");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("fdRiskLevelA");
		eiColumn.setType("C");
		eiColumn.setDescName("A级");
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdRiskLevelB");
		eiColumn.setType("C");
		eiColumn.setDescName("B级");
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdRiskLevelC");
		eiColumn.setType("C");
		eiColumn.setDescName("C级");
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdRiskLevelSum");
		eiColumn.setType("C");
		eiColumn.setDescName("合计");
		eiMetadata.addMeta(eiColumn);
		
		return eiMetadata;
	}
	
	/**
	 * 
	 * <p>Function: getMeta</p>
	 * <p>Description: 构造列 </p>
	 * <p>return value:EiBlockMeta</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-18上午05:36:51 郭淑芳
	 * </p>
	 *
	 */
	private EiBlockMeta getMeta() {
		EiBlockMeta eiMetadata = new EiBlockMeta();
		EiColumn eiColumn = new EiColumn("item");
		eiColumn.setDescName("项目");
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setDescName("个数");
		eiMetadata.addMeta(eiColumn);

		return eiMetadata;
	}
}
